Object Pascal của Apple= Object_Pascal

program ObjectPascalExample;   type      THelloWorld = object         procedure Put;      end;   var      HelloWorld: THelloWorld;   procedure THelloWorld.Put;   begin      ShowMessage('Hello, World!');   end;begin   New(HelloWorld);   HelloWorld.Put;   Dispose(HelloWorld);end.

Object Pascal của Turbo Pascal

Vẫn được hỗ trợ trong Delphi và Free Pascal. FPC cũng đóng gói các thư viện/đơn vị của riêng nói. Nhưng Delphi thì không. Free Pascal 2.0 được viết lại theo phương ngữ giống Delphi hơn.

Cấp phát dựa trên ngăn xếp

program ObjectPascalExample;   type      THelloWorld = object         procedure Put;      end;   procedure THelloWorld.Put;   begin      WriteLn('Hello, World!');   end;var  HelloWorld: THelloWorld; { allocated on the stack and can be used without explicit allocation. }begin   HelloWorld.Put;end.

Cấp phát dựa trên heap

program ObjectPascalExample;   type      PHelloWorld = ^THelloWorld;      THelloWorld = object         procedure Put;      end;   procedure THelloWorld.Put;   begin      WriteLn('Hello, World!');   end;var  HelloWorld: PHelloWorld; { this is a typed pointer to a THelloWorld }begin   New(HelloWorld);   HelloWorld^.Put;   Dispose(HelloWorld);end.

Ví dụ khác:

program ObjectPascalExample;   type      PHelloWorld = ^THelloWorld;      THelloWorld = object         procedure Put;      end;   procedure THelloWorld.Put;   begin      WriteLn('Hello, World!');   end;var  HelloWorld: PHelloWorld; { this is a typed pointer to a THelloWorld }  HelloWorld2: ^THelloWorld; { this is a direct variable to a pointer of the THelloWorld type.                                This variable is type incompatible with PHelloWorld. }   HelloWorld3: ^THelloWorld; { the compiler sees this as being type incompatible with HelloWorld2 *and*                                PHelloWorld. Using the pointer syntax is the only way to declare a type that is                                assignment compatible. }  HelloWorld4: PHelloWorld; { this is type compatible with HelloWorld, but incompatible with the other two variables. }begin   { This works in a similar way as the code above... but it demonstrates the disadvantage of not      using a specific type. The type definition between two variables using the raw pointer      based notation would be seen as "different" by the compiler. }   New(HelloWorld4);   HelloWorld:= HelloWorld4; { this is valid - the type assignment is valid }   HelloWorld2 = HelloWorld; { this would be a compiler error }   {disposes left out for brevity}   New(HelloWorld3);   HelloWorld:= HelloWorld3; { this would be a compiler error }   HelloWorld2 = HelloWorld3; { this would be a compiler error }   {disposes left out for brevity}end.

Đây là một khác biệt quan trọng để tạo ra, và có thể được nhìn nhận là một trong những khác biệt chính dẫn đến phong cách của Delphi để "ẩn" cấp phát heap và kí hiệu con trỏ từ lập trình viên. Delphi đã loại bỏ sự cần thiết của kiểu con trỏ và cú pháp con trỏ bổ sung, nhưng vẫn giữa lại cơ chế xây dựng rõ ràng.

Object Pascal của Delphi và Free Pascal

program ObjectPascalExample;type  THelloWorld = class    procedure Put;  end;procedure THelloWorld.Put;begin  Writeln('Hello, World!');end;var  HelloWorld: THelloWorld;               { this is an implicit pointer }begin  HelloWorld:= THelloWorld.Create;      { constructor returns a pointer to an object of type THelloWorld }  HelloWorld.Put;  HelloWorld.Free;                       { this line deallocates the THelloWorld object pointed to by HelloWorld }end.

Lưu ý rằng xây dựng đối tượng vẫn có sẵn trong Delphi và Free Pascal.

Object Pascal của Oxygene

namespace ObjectPascalExample;   interface   type      ConsoleApp = class         class method Main;      end;      THelloWorld = class         method Put;      end;   implementation   method THelloWorld.Put;   begin      Console.WriteLine('Hello, World!');   end;   class method ConsoleApp.Main;   begin      var HelloWorld:= new THelloWorld;      HelloWorld.Put;   end;end.

Object Pascal của DWScript (còn gọi là Smart Pascal)

type   THelloWorld = class      procedure Put;      begin         PrintLn('Hello, World!');      end   end;var HelloWorld:= THelloWorld.Create;HelloWorld.Put;

Lưu ý rằng hiện thực phương thức có thể được thực hiện ở vị trí riêng biệt như trong các phương ngữ Object Pascal khác.